﻿var bgjhlr = {
    setBtnStatus: function () {
        var row = $('#bgjhgl_grid').datagrid('getSelected');
        if (row && row.id && row.zt) {
            if (row.zt == 1) {//未提交
                $("#bgjhgl_toolbar [name='xzmx']").show();
                $("#bgjhgl_toolbar [name='xg']").show();
                $("#bgjhgl_toolbar [name='tj']").show();
                $("#bgjhgl_toolbar [name='hz']").hide();
                $("#bgjhgl_toolbar [name='sc']").show();
                $("#bgjhgl_toolbar [name='th']").hide();
                $("#btn_jhmx_pldr").show();
            }
            if (row.zt == 2) {//已提交
                $("#bgjhgl_toolbar [name='xzmx']").hide();
                $("#bgjhgl_toolbar [name='xg']").hide();
                $("#bgjhgl_toolbar [name='tj']").hide();
                $("#bgjhgl_toolbar [name='hz']").hide();
                $("#bgjhgl_toolbar [name='sc']").hide();
                $("#bgjhgl_toolbar [name='th']").show();
                $("#btn_jhmx_pldr").hide();
            }
            if (row.zt == 3) {//已汇总
                $("#bgjhgl_toolbar [name='xzmx']").hide();
                $("#bgjhgl_toolbar [name='xg']").hide();
                $("#bgjhgl_toolbar [name='tj']").hide();
                $("#bgjhgl_toolbar [name='hz']").hide();
                $("#bgjhgl_toolbar [name='sc']").hide();
                $("#bgjhgl_toolbar [name='th']").show();
                $("#btn_jhmx_pldr").hide();
            }
        } else {
            $("#bgjhgl_toolbar [name='xzmx']").hide();
            $("#bgjhgl_toolbar [name='xg']").hide();
            $("#bgjhgl_toolbar [name='tj']").hide();
            $("#bgjhgl_toolbar [name='hz']").hide();
            $("#bgjhgl_toolbar [name='sc']").hide();
            $("#bgjhgl_toolbar [name='th']").hide();
            $("#btn_jhmx_pldr").hide();
        }
    }
}


$(function () {
    //======================
    //======设置查询条件========
    //======================
    //计划单位
    $("#bgjhgl_toolbar [name='jhdwId']").qyjgzcombobox();
    //搜索按钮
    $("#bgjhgl_toolbar [name='searchButton']").click(function () {
        reloadBgjhlrGrid();
    });
    //======================
    //========操作按钮========
    //======================
    //批量入账
    $("#btn_jhmx_pldr").click(function () {
        var row = $('#bgjhgl_grid').datagrid("getSelected");
        if (row && row.length != 0) {
            if (row.length > 1) {
                $.messager.alert("提示", "请选择一条物资计划!", "warning");
                return;
            }
            var win = $.window({
                title: "批量导入",
                width: 450,
                height: 240,
                cache: false,
                url: $.webPath() + "/jhgl/bgjhlr/bgjhmx_upload?id=" + row.id,
                modal: true,
                buttons: [
                    {
                        text: '确认',
                        handler: function () {
                            $('#bgjhmx_uploadSubject').form('submit', {
                                onSubmit: function () {
                                    $(win).mask();
                                },
                                success: function (data) {
                                    $(win).mask('hide');
                                    var json = $.parseJSON(data);
                                    if (json.statusCode == 200) {
                                        $(win).window('close');
                                        reloadBgjhlrGrid();
                                        $.messager.show({
                                            title: '提示',
                                            msg: json.message,
                                            timeout: 3000,
                                            showType: 'slide'
                                        });
                                    } else
                                        $.messager.alert('提示', json.message, 'error');
                                }
                            });
                        }
                    }
                ]
            });
        } else
            $.messager.alert("提示", "请先选择要修改的物资计划!", "warning");


    });

    //物资计划新增按钮
    $("#bgjhgl_toolbar [name='xz']").click(function () {
        showBgjhlrDialog("物资计划", $.webPath() + "/jhgl/bgjhlr/bgjhlr_content", $.webPath() + "/jhgl/bgjhlr/save_bgjhlr");
    });
    //计划维护明细按钮
    $("#bgjhgl_toolbar [name='xzmx']").click(function () {
        var row = $('#bgjhgl_grid').datagrid("getSelected");
        if (row && row.length != 0) {
            if (row.length > 1) {
                $.messager.alert("提示", "请选择一条物资计划!", "warning");
                return;
            }
            if (row.zt == 1 && row.hz == 0)
                showBgjhlrmxDialog("维护计划明细", $.webPath() + "/jhgl/bgjhlr/bgjhlr_detail?id=" + row.id, $.webPath() + "/jhgl/bgjhlr/edit");
            else
                $.messager.alert("提示", "请选择未提交的物资计划!", "warning");
        } else
            $.messager.alert("提示", "请先选择要修改的物资计划!", "warning");
    });
    //物资计划修改按钮
    $("#bgjhgl_toolbar [name='xg']").click(function () {
        var row = $('#bgjhgl_grid').datagrid("getSelected");
        if (row && row.length != 0) {
            if (row.length > 1) {
                $.messager.alert("提示", "请选择一条物资计划!", "warning");
                return;
            }
            if (row.zt == 1 && row.hz == 0)
                showBgjhlrDialog("修改保供计划", $.webPath() + "/jhgl/bgjhlr/bgjhlr_content?id=" + row.id, $.webPath() + "/jhgl/bgjhlr/edit");
            else
                $.messager.alert("提示", "请选择未提交的物资计划!", "warning");
        } else
            $.messager.alert("提示", "请先选择要修改的物资计划!", "warning");
    });
    //提交保供计划
    $("#bgjhgl_toolbar [name='tj']").click(function () {
        var row = $('#bgjhgl_grid').datagrid("getSelected");
        if (row) {
            $.messager.confirm('提示', '是否确认提交计划?', function (r) {
                if (r) {
                    $.mask();
                    $.post($.webPath() + "/jhgl/bgjhlr/submit", {ids: row.id}, function (data) {
                        $.mask.hide();
                        if (data.statusCode == 200) {
                            reloadBgjhlrGrid();
                            $.messager.show({title: '提示', msg: data.message, timeout: 3000, showType: 'slide'});
                        } else {
                            $.messager.alert("提示", data.message, "error");
                        }
                    });
                }
            });
        } else {
            $.messager.alert("提示", "请勾选要提交的物资计划!", "warning");
        }
    });
    //物资计划汇总按钮
    $("#bgjhgl_toolbar [name='hz']").click(function () {
        var rows = $(grid).edatagrid('getChecked');
        if (rows.length > 0) {
            var jyjgId = rows[0].jyjgId;
            for (var i = 0; i < rows.length; i++) {
                //判断是否为同一个路径建的计划，如果不同给汇总
                for (var j = 0; j < rows.length; j++) {
                    if (rows[i].lj_id != rows[j].lj_id) {
                        $.messager.alert("提示", "不是同一的路径建的计划不能汇总!", "warning");
                        return;
                    }
                }
                //判断计划是否是同一个运营商
                if (rows[i].jyjgId != jyjgId) {
                    $.messager.alert("提示", "请选择相同运营商的物资计划!", "warning");
                    return;
                }
                //判断是否已经提交
                if (rows[i].zt != 2 || rows[i].hz != 0) {
                    $.messager.alert("提示", "请选择已提交的物资计划!", "warning");
                    return;
                }
            }
            $.messager.confirm('提示', '是否确认汇总计划?', function (r) {
                if (r) {
                    var idArray = $.map(rows, function (value, i) {
                        return  value.id;
                    });
                    $.mask();
                    $.post($.webPath() + "/jhgl/bgjhlr/collect", {ids: idArray.join(",")}, function (data) {
                        $.mask.hide();
                        if (data.statusCode == 200) {
                            reloadBgjhlrGrid();
                            $.messager.show({title: '提示', msg: data.message, timeout: 3000, showType: 'slide'});
                        } else {
                            $.messager.alert("提示", data.message, "error");
                        }
                    });
                }
            });
        } else {
            $.messager.alert("提示", "请勾选要汇总的物资计划!", "warning");
        }
    });
    //物资计划删除按钮
    $("#bgjhgl_toolbar [name='sc']").click(function () {
        var row = $('#bgjhgl_grid').datagrid("getSelected");
        if (row) {
            $.messager.confirm('提示', '是否确认删除计划?', function (r) {
                if (r) {
                    $.mask();
                    $.post($.webPath() + "/jhgl/bgjhlr/delete", {ids: row.id}, function (data) {
                        $.mask.hide();
                        if (data.statusCode == 200) {
                            reloadBgjhlrGrid();
                            $.messager.show({title: '提示', msg: data.message, timeout: 3000, showType: 'slide'});
                        } else {
                            $.messager.alert("提示", data.message, "error");
                        }
                    });
                }
            });
        } else {
            $.messager.alert("提示", "请勾选要删除的物资计划!", "warning");
        }
    });
    //物资计划退回按钮
    $("#bgjhgl_toolbar [name='th']").click(function () {
        var row = $('#bgjhgl_grid').datagrid("getSelected");
        if (row) {
            $.messager.confirm('提示', '是否确认退回计划?', function (r) {
                if (r) {
                    $.mask();
                    $.post($.webPath() + "/jhgl/bgjhlr/reject", {ids: row.id}, function (data) {
                        $.mask.hide();
                        if (data.statusCode == 200) {
                            reloadBgjhlrGrid();
                            $.messager.show({title: '提示', msg: data.message, timeout: 3000, showType: 'slide'});
                        } else {
                            $.messager.alert("提示", data.message, "error");
                        }
                    });
                }
            });
        } else {
            $.messager.alert("提示", "请勾选要退回的物资计划!", "warning");
        }
    });
    //导出明细
    $("#bgjhglmx_toolbar a[name='exp']").click(function () {
        var row = $('#bgjhgl_grid').datagrid("getSelected");
        if (!row) {
            $.messager.alert("提示", "请选择一条记录", "warning");
            return;
        }
        if (row.hz == 0 || row.zt == 1) {
            window.open($.webPath() + "/jhgl/bgjhlr/bgjhhzmx_exp?id=" + row.id + "&&hz=" + row.hz);
        } else {
            // 明细详细信息
            var typeId;
            if (row.hz == 1) {
                typeId = 1;
            }
            if (row.hz != 1) {
                typeId = 2;
            }
            window.open($.webPath() + "/jhgl/bgjhlr/bgjhhzmx_exp?id=" + row.id + "&&typeId=" + typeId + "&&hz=" + row.hz);
        }

    });
    //======================
    //========计划列表========
    //======================
    var grid = $('#bgjhgl_grid').datagrid({
        url: $.webPath() + '/jhgl/bgjhlr/bgjhlrList',
        toolbar: "#bgjhgl_toolbar",
        pagination: true,
        pageSize: 50,
        rownumbers: true,
        checked: true,
        singleSelect: true,
        checkOnSelect: false,
        selectOnCheck: false,
        pageNumber: 1,
        collapsible: true,
        fit: true,
        fitColumns: true,
        queryParams: {
            jhnf: $("#bgjhgl_toolbar [name='jhnf']").val(),
            jhyf: $("#bgjhgl_toolbar [name='jhyf']").val()
        },
        columns: [
            [
                {field: 'lj_id', title: '路径ID', align: 'center', hidden: true, width: $(this).width() * 0.1},
                {field: 'jyjg', title: '运营商', align: 'center', width: $(this).width() * 0.1},
                {field: 'jhdw', title: '下游名称', align: 'center', width: $(this).width() * 0.2},
                {field: 'sm', title: '计划说明', align: 'center', width: $(this).width() * 0.45},
                {field: 'jhny', title: '计划年月', align: 'center', width: $(this).width() * 0.1},
                {field: 'zdr', title: '计划员', align: 'center', width: $(this).width() * 0.05},
                {field: 'bz', title: '备注', align: 'center', width: $(this).width() * 0.05},
                {field: 'zt', title: '状态', align: 'center', width: $(this).width() * 0.05,
                    formatter: function (value, row, index) {
                        if (row.hz == 0) {
                            switch (row.zt) {
                                case 1:
                                    return "未提交";
                                case 2:
                                    return "已提交";
                                case 3:
                                    return "已汇总";
                            }
                        }
                        else {
                            switch (row.zt) {
                                case 1:
                                    return "已汇总";
                                case 2:
                                    return "已提交供应站";
                                case 3:
                                    return "供应站已处理";
                                case 4:
                                    return "业务科已处理";
                                case 5:
                                    return "正在提交";
                                case 6:
                                    return "已经提交至物供";
                                case 7:
                                    return "计划科已处理";
                                case 8:
                                    return "采购单已办理";
                            }
                        }
                        return value;
                    }
                }
            ]
        ],
        checkRow: function (rowIndex, rowData) {
            CheckRowThing();
            bgjhlr.setBtnStatus();
        },
        onLoadSuccess: function () {
            $(this).datagrid('selectRow', 0);
            CheckRowThing();
            bgjhlr.setBtnStatus();

            $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
        },
        onClickRow: function (rowIndex, rowData) {
            CheckRowThing();
            bgjhlr.setBtnStatus();
        }
    });
    //选择一行触发的事件
    function CheckRowThing() {
        var tabs = $("#bgjhgl_tabs").tabs("tabs");
        var row = $('#bgjhgl_grid').datagrid("getSelected");

        // 物资计划明细,没有汇总详细信息
        if (row.hz == 0 || row.zt == 1) {
            var col = [
                {title: '物资编码', field: 'wzgg.code', align: 'center', width: 150},
//                    {title: '物资编码(新)', field: 'wzgg.code', width: 150},
                {title: '物资名称', field: 'wzgg.name', align: 'center', width: 150},
                {title: '材质', field: 'wzgg.cz', align: 'center', width: 150},
                {title: '型号规格', field: 'wzgg.ggxh', align: 'center', width: 150},
                /*{title:'图号', field:'wzgg.th', align:'center', width:60},*/
                {title: '单位', field: 'dw', align: 'center', width: 60},
                {title: '计划件数', field: 'jhjs', align: 'right', width: 80},
                {title: '计划重量', field: 'jhsl', align: 'right', width: 80},
                {title: '到货日期', field: 'dhrq', align: 'center', width: 150},
                {title: '牌号', field: 'ph', align: 'center', width: 100},
                {title: '设备材料', field: 'sbcl', align: 'center', formatter: function (value, row, index) {
                    if (value == 'cl') {
                        return '材料';
                    } else if (value == 'sb') {
                        return '设备';
                    }
                }, width: 140},
//                {title:'计划员', field:'jhy', align:'center', width:200},
//                {title:'是否退回', field:'zt', align:'center', width:150, formatter:function (value, row, index) {
//                    switch (row.zt) {
//                        case 1:
//                            return "否";
//                        case 2:
//                            return "是";
//                        case 3:
//                            return "已汇总";
//                    }
//                }
//                },
                {title: '备注', field: 'bz', align: 'center', width: 150}
            ];
            if (row) {
                $('#bg_wuzjhmx_grid').datagrid({
                    toolbar: "#bgjhglmx_toolbar",
                    pageNumber: 1,
                    url: $.webPath() + "/jhgl/bgjhlr/bgjhhzmxdetail?id=" + row.id + "&&hz=" + row.hz,
                    columns: [col],
                    onLoadSuccess: function () {
                        $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
                    }
                })
            }


        } else {
            // 明细详细信息
            var typeId;
            if ((row.type && row.type.toLowerCase() == 'ydjh' && row.hz == 1)) {
                typeId = 1;
            }
            if ((row.type && row.type.toLowerCase() != 'ydjh' && row.hz != 1)) {
                typeId = 2;
            }
            var col = [
                {title: '物资编码', field: 'wzgg.code', align: 'center', width: 100},
//                    {title: '物资编码(新)', field: 'wzgg.code', width: 100},
                {title: '物资名称', field: 'wzgg.name', align: 'center', width: 90},
                {title: '型号规格', field: 'wzgg.ggxh', align: 'center', width: 90},
                /* {title:'图号', field:'wzgg.th', align:'center', width:60},*/
                {title: '单位', field: 'dw', align: 'center', width: 60},
                {title: '类型', field: 'cgfs', align: 'center', width: 60},
                {title: '计划重量', field: 'jhsl', align: 'right', width: 80},
                {title: '库存数量', field: 'kcsl', align: 'right', width: 80},
                {title: '一级平衡数量', field: 'sl1', align: 'right', width: 80},
                {title: '二级平衡数量', field: 'sl2', align: 'right', width: 80},
                {title: '上报数量', field: 'sbsl', align: 'right', width: 80},
                {title: '到货日期', field: 'dhrq', align: 'center', width: 90},
                {title: '牌号', field: 'ph', align: 'center', width: 90},
                {title: '设备材料', field: 'sbcl', align: 'center', formatter: function (value, row, index) {
                    if (value == 'cl') {
                        return '材料';
                    } else if (value == 'sb') {
                        return '设备';
                    }
                }, width: 90},
                {title: '备注', field: 'bz', align: 'center', width: 90},
                {title: '计划员', field: 'hzr', align: 'center', width: 70},
                {title: '提交人', field: 'hzr', align: 'center', width: 70},
                {title: '提交时间', field: 'hzsj', align: 'center', width: 70},
                {title: '汇总人', field: 'hzr', align: 'center', width: 70},
                {title: '汇总时间', field: 'hzsj', align: 'center', width: 70},
                {title: '供应站处理人', field: 'gyzclr', align: 'center', width: 80},
                {title: '供应站处理时间', field: 'gyzclsj', align: 'center', width: 90},
                {title: '业务科处理人', field: 'ywkclr', align: 'center', width: 80},
                {title: '业务科处理时间', field: 'ywkclsj', align: 'center', width: 90},
                {title: '状态', field: 'zt', width: 90, align: 'center', formatter: function (value, row, index) {
                    switch (row.zt) {
                        case 1:
                            return "已汇总";
                        case 2:
                            return "已提交供应站";
                        case 3:
                            return "供应站已处理";
                        case 4:
                            return "业务科已处理";
                        case 5:
                            return "正在提交";
                        case 6:
                            return "已经提交至物供";
                        case 7:
                            return "计划科已处理";
                        case 8:
                            return "采购单已办理";
                        case 10:
                            return "已退回";
                    }
                }},
                {title: '合同编码', field: 'htbm', width: 100, align: 'center', formatter: function (value, row, index) {
                    if (value)
                        return "<a href='javascript:void(0);' style='color: red' onclick='viewHtDetail(" + row.htid + ")' >" + value + "</a>"
                    else
                        return value;
                }},
                {title: '采购单号', field: 'cgdh', width: 100, align: 'center', formatter: function (value, row, index) {
                    if (value)
                        return "<a href='javascript:void(0);' style='color: red' onclick='viewCgdDetail(" + row.cgdid + ")' >" + value + "</a>"
                    else
                        return value;
                }},
                {title: '验收人', field: 'ysr', width: 80, align: 'center'},
                {title: '验收时间', field: 'yssj', width: 100, align: 'center'}


            ];
            if (row) {
                $('#bg_wuzjhmx_grid').datagrid({
                    pageNumber: 1,
                    toolbar: "#bgjhglmx_toolbar",
                    url: $.webPath() + "/jhgl/bgjhlr/bgjhhzmxdetail?id=" + row.id + "&&typeId=" + typeId + "&&hz=" + row.hz,
                    columns: [col],
                    onLoadSuccess: function () {
                        $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
                    }
                })
            }


        }


        //退回物资计划
        var col = [
            {title: '物资编码', field: 'wzgg.code', align: 'center', width: 150},
//                {title: '物资编码(新)', field: 'wzgg.code', width: 150},
            {title: '物资名称', field: 'wzgg.name', align: 'center', width: 150},
            {title: '型号规格', field: 'wzgg.ggxh', align: 'center', width: 150},
            /*   {title:'图号', field:'wzgg.th', align:'center', width:60},*/
            {title: '单位', field: 'wzgg.dw', align: 'center', width: 60},
            {title: '计划重量', field: 'jhsl', align: 'right', width: 80},
            {title: '退回原因', field: 'bgjhhzmx.thyy', align: 'center', width: 200},
            {title: '退回日期', field: 'bgjhhzmx.thrq', align: 'center', width: 150},
            {title: '退回人', field: 'bgjhhzmx.thr', align: 'center', width: 100},
            {title: '到货日期', field: 'dhrq', align: 'center', width: 150},
            {title: '牌号', field: 'ph', align: 'center', width: 150},
            {title: '设备材料', field: 'sbcl', align: 'center', formatter: function (value) {
                if (value == 'sb') {
                    return "设备";
                }
                if (value == "cl") {
                    return "材料";
                }
            }, width: 150},
            {title: '备注', field: 'bz', align: 'center', width: 150}
        ];
        if (row) {
            $("#bg_wzjhgl_thwzjh_grid").datagrid({
                rownumbers: "true",
                singleSelect: "true",
                showFooter: true,
                fitColumns: true,
                pageNumber: 1,
                url: $.webPath() + "/jhgl/bgjhlr/findThBgjhmxByBgjh?id=" + row.id,
                columns: [col],
                onLoadSuccess: function () {
                    $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
                }
            });
        }
    }

//===========================================
//==============此页面用到的函数===================
//===========================================
    function showBgjhlrDialog(title, href, actionUrl) {
        var win = $.window({
            title: title,
            width: 1024,
            height: 470,
            maximizable: true,
            cache: false,
            url: href,
            modal: true,
            onMaximize: function () {
                $(this).find("#bgjhlrForm").tabs("resize");
            },
            onRestore: function () {
                $(this).find("#bgjhlrForm").tabs("resize");
            },
            onBeforeClose: function () {

            },
            buttons: [
                {
                    text: '保存',
                    handler: function () {
                        $(win).mask();
                        $('#bgjhlrForm').form('submit', {
                            url: actionUrl,
                            onSubmit: function (param) {
                                //验证主信息表单
                                var isValid = $(this).form('validate');
                                if (!isValid) {
                                    $(win).mask('hide');
                                    $('#bgjhlrForm').tabs('select', 0);
                                    return false;
                                }
                                return isValid;
                            },
                            success: function (data) {
                                $(win).mask('hide');
                                var json = $.parseJSON(data);
                                if (json.statusCode == 200) {
                                    $(win).dialog('close');
                                    reloadBgjhlrGrid();
                                    $.messager.show({
                                        title: '提示',
                                        msg: json.message,
                                        timeout: 3000,
                                        showType: 'slide'
                                    });
                                } else {
                                    $.messager.alert('提示', json.message, 'error');
                                }
                            }
                        });
                    }
                }
            ]
        });
    }

    function showBgjhlrmxDialog(title, href, actionUrl) {
        var win = $.window({
            title: title,
            width: 1024,
            height: 470,
            maximizable: true,
            cache: false,
            url: href,
            modal: true,
            onMaximize: function () {
                $(this).find("#bgjhlrForm").tabs("resize");
                $(this).find("#bgjhlr_bgjhmx_edatagrid").edatagrid("resize");
            },
            onRestore: function () {
                $(this).find("#bgjhlrForm").tabs("resize");
                $(this).find("#bgjhlr_bgjhmx_edatagrid").edatagrid("resize");
            },
            buttons: [
                {
                    text: '保存',
                    handler: function () {
                        // $(win).mask();
                        $("#bgjhlr_bgjhmx_edatagrid").edatagrid('saveRow');
                        var bjghmxData = $("#bgjhlr_bgjhmx_edatagrid").edatagrid('getData');
                        for (var i = 0; i < bjghmxData.rows.length - 1; i++) {
                            if (bjghmxData.rows[i]['wzgg.id']) {
                                if (!bjghmxData.rows[i]['cd.id']) {
                                    $.messager.alert("提示", "请填写" + (i + 1) + "行产地!", "waring");
                                    return false;
                                }
                            }
                        }

                        var grid = $('#bgjhlrForm #bgjhlr_bgjhmx_edatagrid');
                        var r = $(grid).edatagrid("getSelected");
                        var index = $(grid).edatagrid("getRowIndex", r);
                        $(grid).edatagrid("endEdit", index);
                        var data = $(grid).edatagrid("getData");
                        if (!data.rows.length) {
                            $(win).mask('hide');
                            $.messager.alert("提示", "请填写物资计划明细!", "waring");
                            $('#bgjhlrForm').tabs('select', 1);
                            return false;
                        }

                        for (var i = 0; i < data.rows.length; i++) {
                            if (data.rows[i]['wzgg.code']) {

                                var rowIndex = $(grid).edatagrid('getRowIndex', data.rows[i]);
                                if (!data.rows[i]['jhsl'] || isNaN(parseFloat(data.rows[i]['jhsl'])) || parseFloat(data.rows[i]['jhsl']) == 0) {
                                    $(win).mask('hide');
                                    $.messager.alert("提示", "请填写第" + (rowIndex + 1) + "行物资计划明细计划重量!", "waring");
                                    $('#bgjhlrForm').tabs('select', 1);
                                    return false;
                                }
                            }

                            if (!data.rows[i]['wzgg.id']) {
                                $(grid).edatagrid("endEdit", index);
                            }
                        }
                        $(win).mask('hide');
                        $(win).dialog('close');
                        reloadBgjhlrGrid();
                        $.messager.show({title: '提示', msg: "物资计划明细维护成功！", timeout: 3000, showType: 'slide'});
                    }
                }
            ]
        });
    }

    // 刷新表格
    function reloadBgjhlrGrid() {
        $('#bgjhgl_grid').datagrid('reload', {
            jhdwId: $("#bgjhgl_toolbar [name='jhdwId']").val(),
            jhnf: $("#bgjhgl_toolbar [name='jhnf']").val(),
            jhyf: $("#bgjhgl_toolbar [name='jhyf']").val(),
            wzbm: $("#bgjhgl_toolbar [name='wzbm']").val(),
            sm: $("#bgjhgl_toolbar [name='sm']").val(),
            startDate: $("#bgjhgl_toolbar [name='startDate']").val(),
            endDate: $("#bgjhgl_toolbar [name='endDate']").val(),
            sssbcl: $("#sssbcl").combobox("getValue")
        });
    }

});

function viewHtDetail(id) {
    $.window({
        title: '详细信息',
        iconCls: 'icon-tip',
        url: $.webPath() + "/htgl/cghtgl/cghtgl_detail?cghtId=" + id,
        width: 1050,
        height: 500,
        modal: true,
        isMax: false
    })
}

function viewCgdDetail(id) {
    $.window({
        title: '详细信息',
        iconCls: 'icon-tip',
        url: $.webPath() + "/cggl/cgdgl/cgdgl_detail?cgd.id=" + id,
        width: 1050,
        height: 500,
        modal: true,
        isMax: false
    })
}